package xyz.xmh.pattern.j2ee.dataaccessobjectpattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * <p>
 * 实现数据接口的实体类
 */
public class StudentDaoImpl implements StudentDao {

    private final List<Student> studentList;

    public StudentDaoImpl() {
        studentList = new ArrayList<>();
        Student student1 = new Student("Robert", 0);
        Student student2 = new Student("John", 1);
        studentList.add(student1);
        studentList.add(student2);
    }

    @Override
    public List<Student> listStudents() {
        return studentList;
    }

    @Override
    public Student getStudent(int rollNo) {
        return studentList.get(rollNo);
    }

    @Override
    public void updateStudent(Student student) {
        studentList.get(student.getRollNo()).setName(student.getName());
    }

    @Override
    public void deleteStudent(Student student) {
        studentList.remove(student.getRollNo());
    }
}
